package cn.itcast.controller;

import cn.itcast.Annotation.Cache;
import cn.itcast.entity.Result;
import cn.itcast.pojo.Order;
import cn.itcast.service.OrderService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    //分页条件查询
    @Cache
    @GetMapping("/findPage")
    public Result findPage(@RequestParam Map map){

        Result result =  orderService.findPage(map);

        return result;
    }

    //添加
    @PostMapping("/submit")
    public Result insert(@RequestBody Order order){

        System.out.println(order);

        Integer i = orderService.insert(order);
        System.out.println(i);

        return i>0? new Result(true,"添加成功"):new Result(false,"添加失败");
    }

    //编辑回显数据
    @Cache
    @GetMapping("/{id}")
    public Result handleUpdate(@PathVariable("id") String id){
        Result result = orderService.findById(id);
        return result;
    }

//    更换就诊状态
    @Cache
    @GetMapping("/updateArrival")
    public Result updateArrival(@RequestParam Map map){
        String id = map.get("id").toString();

        Integer arrival = Integer.parseInt(map.get("arrival").toString());
        Result result = orderService.updateArrival(id,arrival);
        return result;
    }
}
